/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pa165.languageschool;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Tomas Hruby & Elena Medvedeva
 */

@Stateless
public class StudentDao implements StudentDaoLocal{
    
    @PersistenceContext
    private EntityManager em;

    @Override
    public Student add(Student student) {
      if(student == null){
            throw new IllegalArgumentException("Method StudentDao.add call with Null argument student");
      }
       em.persist(student);
       return student;
    }

    @Override
    public Student get(Long id) {
        if(id == null){
          throw new IllegalArgumentException("Method StudentDao.get call with Null argument id");           
        }
         return em.find(Student.class, id);
    }

    @Override
    public List<Student> getAll() {
         return em.createQuery( "SELECT st FROM Student st", Student.class ).getResultList();
    }
}
